#/bin/bash

#根据table的名字，返回table所在的目录
mysql_datadir=$(/opt/mysql/bin/mysql -e "show variables like '%datadir%'"|awk 'NR==2{print $2}')
#table_types=("NPE_RECORD" "RGWALL_URL" "RGWALL_NAT" "ACE_URL" "IPFIX" "IM" "RGEG_IM" "RGEG_MAIL" "RGEG_WEBBBS" "RGEG_URL" "RGEG_NAT")

is_table_exist=$(/opt/mysql/bin/mysql -e "select count(*) from information_schema.TABLES where TABLE_NAME='$1'"|awk 'NR==2{print}')
if [[ $is_table_exist == 0 ]]; then
	echo "the table you input is not exist"
	exit 1
fi
input_table="$1"
table_name=$(echo $1|awk -F"2" '{print $1}')   #这里取出的table_name结尾多一个下划线_
table_date=${input_table:${#table_name}:8}
#去掉table_name的下划线
table_name=${table_name:0:$((${#table_name}-1))}

#计算table_date是一年中的第几天
day_of_year=$(date +"%j" --date="$table_date")
dir=$(expr $day_of_year % 90)
echo "${mysql_datadir}DATA/${table_name}/${dir}/"


